feat(apiserver): implement APIService caBundle reconciliation#1808
feat(apiserver): implement APIService caBundle reconciliation#1808praveenrewar merged 5 commits intocarvel-dev:developfrom
Conversation
497ff62 to
8c4fa11
Compare
There was a problem hiding this comment.
Pull request overview
This PR implements continuous, idempotent APIService caBundle reconciliation to fix a race condition that occurs during rolling upgrades or node drains. Previously, kapp-controller performed a one-time sync at startup, which could be overwritten by a terminating old pod, permanently breaking the packaging API routing. The solution introduces a background reconciliation loop that continuously ensures the active pod's certificate is the source of truth.
Changes:
- Registered
apiservice-ca-reconcileras a PostStartHook that performs initial caBundle sync before the server reports ready, followed by a background goroutine that polls every 30 seconds - Modified
updateAPIServiceto accept a context parameter and perform an idempotentbytes.Equal()check to avoid unnecessary API updates when the bundle hasn't changed - Updated
newServerConfigreturn type to include thecaContentProviderso it can be passed to the background reconciliation loop - Added comprehensive unit tests covering both update and no-op scenarios
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| pkg/apiserver/apiserver.go | Added PostStartHook for APIService CA reconciliation with initial sync and background polling; modified function signatures and return types to support passing caContentProvider |
| pkg/apiserver/apiserver_test.go | New test file with unit tests for updateAPIService function, covering drift detection and idempotent update scenarios |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
40380d6 to
07103cb
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
ecd6043 to
c058e14
Compare
Signed-off-by: Himanshu Singh <himansh.singh3@gmail.com>
Signed-off-by: Himanshu Singh <himansh.singh3@gmail.com>
Signed-off-by: Himanshu Singh <himansh.singh3@gmail.com>
Signed-off-by: Himanshu Singh <himansh.singh3@gmail.com>
5fc7c7b to
dd75238
Compare
Signed-off-by: Himanshu Singh <himansh.singh3@gmail.com>
dd75238 to
baecdc3
Compare
What this PR does / why we need it:
Currently, kapp-controller executes a one-time patch of the v1alpha1.data.packaging.carvel.dev APIService object during pod initialization to inject its self-signed CA bundle.
During a rolling upgrade or node drain, a race condition occurs if an old pod restarts or terminates concurrently with the new pod booting up. The terminating pod can inadvertently overwrite the APIService with an invalid or dying caBundle after the new pod has completed its one-time sync. This permanently breaks internal cluster routing to the packaging API until the new pod is manually restarted.
This PR resolves the issue by moving from a one-time boot sync to a continuous, idempotent background reconciliation loop, ensuring the active pod continuously acts as the source of truth for the APIService configuration.
Which issue(s) this PR fixes:
Fixes #1807
Does this PR introduce a user-facing change?
Fixed a race condition during rolling upgrades that could cause the
kapp-controllerpackaging API routing to permanently break due to APIService CA bundle drift.Additional Notes for your reviewer:
Review Checklist:
a link to that PR
change
Additional documentation e.g., Proposal, usage docs, etc.:
NONE
Testing